package com.imonsoft.sqm.dao.business.supplier_quality;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import org.springframework.stereotype.Repository;

import com.imonsoft.common.constant.ConstantDict;
import com.imonsoft.common.httpModel.DataGrid;
import com.imonsoft.common.httpModel.Pager;
import com.imonsoft.common.util.StringUtil;
import com.imonsoft.sqm.pojo.basedata.Dictionary;
import com.imonsoft.sqm.pojo.business.supplier_quality.AnswerProblem;
import com.imonsoft.sqm.pojo.business.supplier_quality.AnswerProblemExample;
import com.imonsoft.sqm.service.basedata.DictionaryService;
import com.imonsoft.sqm.vo.business.supplier_quality.AnswerProblemVo;
@SuppressWarnings("deprecation")
@Repository("answerProblemDAO")
public class AnswerProblemDAOImpl extends SqlMapClientDaoSupport implements AnswerProblemDAO {

	@Autowired
	private DictionaryService dictionaryService;
    /**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table tt_response_on_problem
	 * @ibatorgenerated  Wed Jun 05 17:17:41 CST 2013
	 */
	public AnswerProblemDAOImpl() {
		super();
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table tt_response_on_problem
	 * @ibatorgenerated  Wed Jun 05 17:17:41 CST 2013
	 */
	public int countAnswerProblemByExample(AnswerProblemExample example) {
		Integer count = (Integer) getSqlMapClientTemplate().queryForObject("tt_response_on_problem.ibatorgenerated_countByExample", example);
		return count;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table tt_response_on_problem
	 * @ibatorgenerated  Wed Jun 05 17:17:41 CST 2013
	 */
	public int deleteAnswerProblemByExample(AnswerProblemExample example) {
		int rows = getSqlMapClientTemplate().delete("tt_response_on_problem.ibatorgenerated_deleteByExample", example);
		return rows;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table tt_response_on_problem
	 * @ibatorgenerated  Wed Jun 05 17:17:41 CST 2013
	 */
	public int deleteAnswerProblemByPrimaryKey(Long id) {
		AnswerProblem key = new AnswerProblem();
		key.setId(id);
		int rows = getSqlMapClientTemplate().delete("tt_response_on_problem.ibatorgenerated_deleteByPrimaryKey", key);
		return rows;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table tt_response_on_problem
	 * @ibatorgenerated  Wed Jun 05 17:17:41 CST 2013
	 */
	public Long insertAnswerProblem(AnswerProblem record) {
		Object newKey = getSqlMapClientTemplate().insert("tt_response_on_problem.ibatorgenerated_insert", record);
		return (Long) newKey;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table tt_response_on_problem
	 * @ibatorgenerated  Wed Jun 05 17:17:41 CST 2013
	 */
	public Long insertAnswerProblemSelective(AnswerProblem record) {
		Object newKey = getSqlMapClientTemplate().insert("tt_response_on_problem.ibatorgenerated_insertSelective", record);
		return (Long) newKey;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table tt_response_on_problem
	 * @ibatorgenerated  Wed Jun 05 17:17:41 CST 2013
	 */
	@SuppressWarnings("unchecked")
	public List<AnswerProblem> selectAnswerProblemByExample(AnswerProblemExample example) {
		List<AnswerProblem> list = getSqlMapClientTemplate().queryForList("tt_response_on_problem.ibatorgenerated_selectByExample", example);
		return list;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table tt_response_on_problem
	 * @ibatorgenerated  Wed Jun 05 17:17:41 CST 2013
	 */
	public AnswerProblem selectAnswerProblemByPrimaryKey(Long id) {
		AnswerProblem key = new AnswerProblem();
		key.setId(id);
		AnswerProblem record = (AnswerProblem) getSqlMapClientTemplate().queryForObject("tt_response_on_problem.ibatorgenerated_selectByPrimaryKey", key);
		return record;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table tt_response_on_problem
	 * @ibatorgenerated  Wed Jun 05 17:17:41 CST 2013
	 */
	public int updateAnswerProblemByExampleSelective(AnswerProblem record, AnswerProblemExample example) {
		UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
		int rows = getSqlMapClientTemplate().update("tt_response_on_problem.ibatorgenerated_updateByExampleSelective", parms);
		return rows;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table tt_response_on_problem
	 * @ibatorgenerated  Wed Jun 05 17:17:41 CST 2013
	 */
	public int updateAnswerProblemByExample(AnswerProblem record, AnswerProblemExample example) {
		UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
		int rows = getSqlMapClientTemplate().update("tt_response_on_problem.ibatorgenerated_updateByExample", parms);
		return rows;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table tt_response_on_problem
	 * @ibatorgenerated  Wed Jun 05 17:17:41 CST 2013
	 */
	public int updateAnswerProblemByPrimaryKeySelective(AnswerProblem record) {
		int rows = getSqlMapClientTemplate().update("tt_response_on_problem.ibatorgenerated_updateByPrimaryKeySelective", record);
		return rows;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table tt_response_on_problem
	 * @ibatorgenerated  Wed Jun 05 17:17:41 CST 2013
	 */
	public int updateAnswerProblemByPrimaryKey(AnswerProblem record) {
		int rows = getSqlMapClientTemplate().update("tt_response_on_problem.ibatorgenerated_updateByPrimaryKey", record);
		return rows;
	}

	/**
	 * This class was generated by Apache iBATIS ibator. This class corresponds to the database table tt_response_on_problem
	 * @ibatorgenerated  Wed Jun 05 17:17:41 CST 2013
	 */
	private static class UpdateByExampleParms extends AnswerProblemExample {
		private Object record;

		public UpdateByExampleParms(Object record, AnswerProblemExample example) {
			super(example);
			this.record = record;
		}

		public Object getRecord() {
			return record;
		}
	}

	@SuppressWarnings("unchecked")
	@Override
	public DataGrid<AnswerProblemVo> getDataGridVoBy(AnswerProblem answerProblem, Pager pager) {

		Integer count = (Integer) getSqlMapClientTemplate().queryForObject("tt_response_on_problem.ibatorgenerated_countByResponse", answerProblem);
		List<AnswerProblemVo> rows = getSqlMapClientTemplate().queryForList("tt_response_on_problem.ibatorgenerated_selectByResponse", answerProblem, pager.getSkipResults(), pager.getRows());
		for (AnswerProblemVo answerProblemVo : rows) {

			List<Dictionary> d1 = dictionaryService.findDictionaryByType(ConstantDict.AnswerProblem_ANSER);

			if (!StringUtil.isBlank(answerProblemVo.getJanuary())) {
				for (Dictionary dictionary : d1) {
					if (dictionary.getCode().equals(answerProblemVo.getJanuary())) {
						answerProblemVo.setJanuary(dictionary.getName());
					}
				}
			}

			if (!StringUtil.isBlank(answerProblemVo.getFebruary())) {
				for (Dictionary dictionary : d1) {
					if (dictionary.getCode().equals(answerProblemVo.getFebruary())) {
						answerProblemVo.setFebruary(dictionary.getName());
					}
				}
			}

			if (!StringUtil.isBlank(answerProblemVo.getMarch())) {
				for (Dictionary dictionary : d1) {
					if (dictionary.getCode().equals(answerProblemVo.getMarch())) {
						answerProblemVo.setMarch(dictionary.getName());
					}
				}
			}

			if (!StringUtil.isBlank(answerProblemVo.getApril())) {
				for (Dictionary dictionary : d1) {
					if (dictionary.getCode().equals(answerProblemVo.getApril())) {
						answerProblemVo.setApril(dictionary.getName());
					}
				}
			}

			if (!StringUtil.isBlank(answerProblemVo.getMay())) {
				for (Dictionary dictionary : d1) {
					if (dictionary.getCode().equals(answerProblemVo.getMay())) {
						answerProblemVo.setMay(dictionary.getName());
					}
				}
			}

			if (!StringUtil.isBlank(answerProblemVo.getJune())) {
				for (Dictionary dictionary : d1) {
					if (dictionary.getCode().equals(answerProblemVo.getJune())) {
						answerProblemVo.setJune(dictionary.getName());
					}
				}
			}

			if (!StringUtil.isBlank(answerProblemVo.getJuly())) {
				for (Dictionary dictionary : d1) {
					if (dictionary.getCode().equals(answerProblemVo.getJuly())) {
						answerProblemVo.setJuly(dictionary.getName());
					}
				}
			}

			if (!StringUtil.isBlank(answerProblemVo.getAugust())) {
				for (Dictionary dictionary : d1) {
					if (dictionary.getCode().equals(answerProblemVo.getAugust())) {
						answerProblemVo.setAugust(dictionary.getName());
					}
				}
			}

			if (!StringUtil.isBlank(answerProblemVo.getSeptember())) {
				for (Dictionary dictionary : d1) {
					if (dictionary.getCode().equals(answerProblemVo.getSeptember())) {
						answerProblemVo.setSeptember(dictionary.getName());
					}
				}
			}

			if (!StringUtil.isBlank(answerProblemVo.getOctober())) {
				for (Dictionary dictionary : d1) {
					if (dictionary.getCode().equals(answerProblemVo.getOctober())) {
						answerProblemVo.setOctober(dictionary.getName());
					}
				}
			}

			if (!StringUtil.isBlank(answerProblemVo.getNovember())) {
				for (Dictionary dictionary : d1) {
					if (dictionary.getCode().equals(answerProblemVo.getNovember())) {
						answerProblemVo.setNovember(dictionary.getName());
					}
				}
			}

			if (!StringUtil.isBlank(answerProblemVo.getDecember())) {
				for (Dictionary dictionary : d1) {
					if (dictionary.getCode().equals(answerProblemVo.getDecember())) {
						answerProblemVo.setDecember(dictionary.getName());
					}
				}
			}

		}
		DataGrid<AnswerProblemVo> dataGrid = new DataGrid<AnswerProblemVo>(count, rows);
		return dataGrid;
	}
}